package com.lgc.webtest.enums;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

@Getter
public enum ErrorCodeEnum {
    SUCCESS("0","成功"),
    NO_PAGE_404("404","地址错误"),
    RPC_ERROR("999","远程调用错误"),
    ERROR("1000","系统内部错误"),
    PARAM_ERROR("1001", "参数错误"),
    REPEAT_CALL("1002", "重复调用"),
    SQL_EXECUTE_ERROR("1003", "数据库错误"),
    DB_DATA_ERROR("1004", "数据库中数据错误");// 数据库错误

    final String code;
    final String msg;
    ErrorCodeEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private static Map<String, String> map = null;
    static {
        map =new HashMap<>();
        for (ErrorCodeEnum item :
                ErrorCodeEnum.values()) {
            map.put(item.getCode(), item.getMsg());
        }
    }

    public static String getNameByCode(String code) {
        return map.containsKey(code) ? map.get(code) : "系统错误";
    }
}
